/**
 * 添加或者修改页面
 */
var OrderPutInfoDlg = {
    data: {
        completeName: ""
    }
};

layui.use(['form', 'admin', 'ax','upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload; //得到 upload 对象
    var layer = layui.layer;

    //让当前iframe弹层高度适应
    admin.iframeAuto();
    
    //选完文件后不自动上传
    $('#test9').click(function () {
    	if($("#operateId").val() == ''){
			Feng.error("请先选择对应项目！");
			return false;
		}

		if(!document.getElementById("test8").files[0]){
			Feng.error("请先上传附件！");
			return false;
		}
		var  index = layer.msg('文件处理中。。。请耐心等待', {
			  icon: 16,
			  shade: [0.2,'#000'], //0.1透明度的白色背景
			  time: false
		});
    	var formdata = new FormData();
    	formdata.append('file', document.getElementById("test8").files[0]);
    	formdata.append('operateId', $("#operateId").val());
    	$.ajax({
    		type: 'Post',
    		data:formdata,
    		cache: false,//上传文件无需缓存
    		processData:false, //告诉jQuery不要去处理发送的数据
    		contentType:false,
        	url: Feng.ctxPath + "/tDispatch/importExcel",
    		success: function (data) {
        		layer.close(index);
        		if (data.success){
        			let message = "匹配成功并已提报";
        			if(data.code == 555){
						message = "匹配存在失败记录，可以下载结果查看具体信息";
					}
					var msg =  layer.open({
						title: '提示' ,
						content: message,
						btn: ['确定','下载结果'],
						yes: function (){
							layer.close(msg);
						},
						btn2: function(){
							if(data.data){
								window.location.href = Feng.ctxPath + "/tDispatch/downFileByFileName?fileName=" + data.data;
							}
						},
						end: function () {
							var Indexs = parent.layer.getFrameIndex(window.name);
							parent.layer.close(Indexs);
						}
					});
        		} else {
        			if (data.message !=null &&data.message!='') {
        				var msg =  layer.open({
    	  					  title: '提示' ,
    	  					  content: data.message,
    	  					  btn: ['确定'],
    	  					  yes: function (){
    	  						  	layer.close(msg);
    	  					  }
        				});     
					} else {
		                    Feng.error("导入失败！");
					}
        		}
    		},
        	error: function(data){
        		layer.close(index);
                Feng.error("网络异常，请稍后重试！" + data.responseJSON.message)
          }
    	});
    });
    
    //返回按钮
    $("#backupPage").click(function () {
    	var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    });
    
    $(".a-upload").on("change","input[type='file']",function(){
        $(".showFileName").html("");
        var filePath=$(this).val();
        if(filePath.indexOf("xls")!=-1 || filePath.indexOf("xlsx")!=-1){
            var arr=filePath.split('\\');
            var fileName=arr[arr.length-1];
            $(".showFileName").html(fileName);
        }else{
            $(".showFileName").html("您未上传文件，或者您上传文件类型有误！");
            return false 
        }
    })

});